<?php

namespace app\api\listener;

use app\common\model\Business;
use app\common\model\Order;

class BusinessScore
{
    public function handle($data)
    {
        $map = ['business_id' => $data['business_id'], 'status' => 5];
        Business::update([
            'id'              => $data['business_id'],
            'describe_score'  => Order::where($map)->avg('describe_score'),
            'logistics_score' => Order::where($map)->avg('logistics_score'),
            'service_score'   => Order::where($map)->avg('service_score')
        ]);
    }
}